import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class L78 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        List<List<Integer>> subsets = new Solution().subsets(nums);
        for (List<Integer> subset : subsets) {
            System.out.println(subset.toString());
        }

    }

    static class Solution {
        private List<List<Integer>> result = new ArrayList<>();
        private LinkedList<Integer> tmp = new LinkedList<>();

        public List<List<Integer>> subsets(int[] nums) {
            backTrack(nums, 0);
            return result;
        }

        private void backTrack(int[] nums, int index) {
            result.add(new LinkedList<>(tmp));

            if (index == nums.length) {
                return;
            }

            for (int i = index; i < nums.length; i++) {
                tmp.add(nums[i]);
                backTrack(nums, i + 1);
                tmp.removeLast();
            }

        }
    }
}
